using System;
using System.Collections.Generic;
using System.Text;
using System.CodeDom;
using System.Web.Compilation;
using System.Web.UI;

namespace AspNetExtensions.ExpressionBuilders
{
    /// <summary>
    /// Allows you to use raw code to assign values to control properties.
    /// </summary>
    /// <remarks>
    /// Add this to the web.config file:
    /// <![CDATA[
    /// <compilation debug="true">
    ///     <expressionBuilders>
    ///         <add expressionPrefix="Code" type="AspNetExtensions.ExpressionBuilders.CodeExpressionBuilder"/>
    ///     </expressionBuilders>
    /// </compilation>
    /// </remarks>]]>
    /// Then use like this:
    /// <![CDATA[
    /// <asp:CheckBox id="chk1" runat="server" Text="<%$ Code: DateTime.Now %>" /
    /// ]]>
    /// You can also try:
    /// <%$ Code: DateTime.Now.AddDays(1) %>
    /// <%$ Code: "Hello World, " + CurrentUserName %>
    /// <%$ Code: CurrentUserName.ToUpper() %>
    /// <%$ Code: "Page compiled as: " + this.GetType().AssemblyQualifiedName %>
    [ExpressionPrefix("Code")]
    public class CodeExpressionBuilder : ExpressionBuilder
    { 
        public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context) 
        { 
            return new CodeSnippetExpression(entry.Expression); 
        } 
    }
}
